﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace RaProWorld
{
    public class SubMenu1
    {
        ContentManager Content;
        Texture2D[] sprites;
        Vector2 position;
        public int status;
        SpriteFont scoreFont;
        Score_Font[] scoreFonts;
        SubMenuButton startButton;
        SubMenuButton anleitungsButton;
        SubMenuButton abbrechenButton;
        public int action;
        string gameName;

        public SubMenu1(Vector2 newPosition,Score score_u,string newGameName) 
        {
            Content = new ContentManager(Program.raProWorld.Services, "Content\\Submenu1");
            sprites = new Texture2D[5];
            position = new Vector2(newPosition.X+80.0f,newPosition.Y-150.0f);
            loadContent();
            startButton = new SubMenuButton(sprites[2], new Vector2(position.X - 61.0f, position.Y - 18.0f));
            anleitungsButton = new SubMenuButton(sprites[3], new Vector2(position.X - 61.0f, position.Y + 16.0f));
            abbrechenButton = new SubMenuButton(sprites[4], new Vector2(position.X - 61.0f, position.Y + 50.0f));
            status = 0;
            action = 0;
            gameName = newGameName;
            scoreFonts = new Score_Font[4];
            scoreFonts[0] = new Score_Font(score_u.getScore(), new Vector2(position.X + 31.0f, position.Y - 29.0f), scoreFont);
            scoreFonts[1] = new Score_Font(score_u.gold, new Vector2(position.X + 30.0f, position.Y + 6.0f), scoreFont);
            scoreFonts[2] = new Score_Font(score_u.silver, new Vector2(position.X + 30.0f, position.Y + 36.0f), scoreFont);
            scoreFonts[3] = new Score_Font(score_u.bronze, new Vector2(position.X + 30.0f, position.Y + 66.0f), scoreFont);
            
        }

        private void loadContent() 
        {
            sprites[0] = Content.Load<Texture2D>("interface1_1");
            sprites[1] = Content.Load<Texture2D>("interface1_2_test");
            sprites[2] = Content.Load<Texture2D>("startbutton");
            sprites[3] = Content.Load<Texture2D>("anleitungbutton");
            sprites[4] = Content.Load<Texture2D>("abbrechenbutton");
            scoreFont = Content.Load<SpriteFont>("scorefont");
        }

        public void Update() 
        {
            if (status == 0) 
            {
                startButton.active = true;
                anleitungsButton.active = false;
                abbrechenButton.active = false;
            }
            if (status == 1) 
            {
                startButton.active = false;
                anleitungsButton.active = true;
                abbrechenButton.active = false;
            }
            if (status == 2)
            {
                startButton.active = false;
                anleitungsButton.active = false;
                abbrechenButton.active = true;
            }
            startButton.Update();
            abbrechenButton.Update();
            anleitungsButton.Update();
        }

        public void Draw(SpriteBatch spriteBatch) 
        {

            spriteBatch.Draw(sprites[0],
                position,
                null,
                new Color(255.0f, 255.0f, 255.0f, 1.0f),
                0.0f,
                new Vector2(sprites[0].Width / 2, sprites[0].Height / 2),
                1.0f,
                SpriteEffects.None,
                0.0f);
            spriteBatch.Draw(sprites[1],
                new Vector2(position.X+76.0f,position.Y+ 47.0f),
                null,
                new Color(255.0f, 255.0f, 255.0f, 1.0f),
                0.0f,
                new Vector2(sprites[1].Width / 2, sprites[1].Height / 2),
                1.0f,
                SpriteEffects.None,
                0.0f);
            startButton.Draw(spriteBatch);
            anleitungsButton.Draw(spriteBatch);
            abbrechenButton.Draw(spriteBatch);
            //Highscore
            scoreFonts[0].Draw(spriteBatch);
            scoreFonts[1].Draw(spriteBatch);
            scoreFonts[2].Draw(spriteBatch);
            scoreFonts[3].Draw(spriteBatch);
            spriteBatch.DrawString(scoreFont,
                gameName,
                new Vector2(position.X - 99.0f, position.Y - 68.0f),
                Color.Black);
            spriteBatch.DrawString(scoreFont,
                gameName,
                new Vector2(position.X - 100.0f, position.Y - 69.0f),
                Color.White);

        }
    }
}
